package com.youchuang.action.admin;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.bean.Product;
import com.youchuang.common.Constant;
import com.youchuang.service.AdminService;

/**
 * 用户订单删除
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/admin")
@ParentPackage("shopping-default")
public class BookUpdateAction extends BaseAction {
	private static final Logger logger = Logger.getLogger(BookUpdateAction.class.getSimpleName());

	@Resource
	private AdminService adminService;

	private String id;
	private String productName;
	private String fixedPrice;
	private String dangPrice;
	private String keyWords;

	@Action(value = "updateProduct", results = {
			@Result(name = Constant.SUCCESS, type = "json", params = { "root", "resultObj" }) })
	public String execute() throws Exception {
		logger.info("method is execute");

		Product product = adminService.findProductById(id);
		if (product == null) {
			product = new Product();
		}
		product.setProductName(productName);
		product.setFixedPrice(Double.parseDouble(fixedPrice));
		product.setDangPrice(Double.parseDouble(dangPrice));
		product.setKeyWords(keyWords);

		adminService.updateProduct(product);
		return Constant.SUCCESS;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public String getFixedPrice() {
		return fixedPrice;
	}

	public void setFixedPrice(String fixedPrice) {
		this.fixedPrice = fixedPrice;
	}

	public String getDangPrice() {
		return dangPrice;
	}

	public void setDangPrice(String dangPrice) {
		this.dangPrice = dangPrice;
	}

	public String getKeyWords() {
		return keyWords;
	}

	public void setKeyWords(String keyWords) {
		this.keyWords = keyWords;
	}

}
